﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using ECCIT.Extension.Weibo_v2.Common;
using ECCIT.Extension.Weibo_v2.Configuration;
using ECCIT.Extension.Weibo_v2.Lib;
using ECCIT.Extension.Weibo_v2.Model;

namespace ECCIT.Extension.Weibo_v2.Lib.Test
{
    using Environment = ECCIT.Extension.Weibo_v2.Configuration.Environment;

    /// <summary>
    /// UnitTest1 的摘要说明
    /// </summary>
    [TestClass]
    public class MicroBlogTest
    {
        private const long C_USERID_NICK = 2393053602;
        private const long C_USERID_CANDY = 2527935682;

        public MicroBlogTest ()
        {
        }

        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，该上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        //
        // 编写测试时，可以使用以下附加特性:
        //
        // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // 在运行每个测试之前，使用 TestInitialize 来运行代码
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // 在每个测试运行完之后，使用 TestCleanup 来运行代码
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestInitialize]
        public void InitTest()
        {
            // If the appKey does not pass the verification, this call would fail with error: 21326 unauthorized_client
            //var accessToken = Microblog.GetAccessTokenByPassword("someone_ly@hotmail.com", "Honey815!");
            //Environment.AccessToken = accessToken;
        }

        [TestMethod]
        public void TestGetUserStatuses()
        {
            var statuses = Microblog.GetUserStatuses(long.Parse(Environment.AccessToken.UserID), null, null, null, null, StatusType.All, false, false);

            Assert.IsNotNull(statuses);
        }

        [TestMethod]
        public void TestUserIDsSerialization()
        {
            string jsonStr = "{\"ids\":[1726475555,1404376560,1233616152], \"total_number\": 668}";
            UserIDs userIDs = JsonSerializationHelper.JsonToObject<UserIDs>(jsonStr);
            Assert.AreEqual(3, userIDs.IDs.Count);
            Assert.AreEqual(0, userIDs.NextCursor);
            Assert.AreEqual(0, userIDs.PreviousCursor);
        }
    }
}
